#ifndef NETWORKCONFIG_H
#define NETWORKCONFIG_H

#include <QString>
#include <QObject>

class QProcess;

/*! Generic network configuration module. It starts setting up when the
 * setup() slot is called. When the configuration is done, the done() signal
 * is emitted. The calling class can then use the address() and port() methods
 * to configure the sharing server.
 */
class NetworkConfig : public QObject
{
Q_OBJECT

public:
    /*! Returns the port to listen on */
    virtual int port() = 0;
    /*! Returns the address of the server (for other clients) */
    virtual QString address() = 0;

public slots:
    /*! Starts the setup process */
    virtual void setup() = 0;

signals:
    /*! Emitted when the network configuration is finished */
    void done();
};

/*!
 * Dummy network config used for debugging. Always returns 127.0.0.1:3530.
 * In the future, this class should be used to implement a static configuration
 * which can be used, for example, for LAN configuration.
 */
class OfflineNetworkConfig : public NetworkConfig
{
Q_OBJECT

public:
    int port();
    QString address();

public slots:
    void setup();

signals:
    void done();
};

/*!
 * This one uses miniupnpc to configure automatically a UPNP-compatible router
 * and returns the newly opened port.
 * */
class UPNPNetworkConfig : public NetworkConfig
{
Q_OBJECT

public:
    UPNPNetworkConfig();
    int port();
    QString address();

public slots:
    void setup();

signals:
    void done();

private slots:
    void listFinished();

private:
    QProcess* process;
    QString localAddress;
    QString externalAddress;
    int _port;

};

#endif // NETWORKCONFIG_H
